package com.qf.zyh.web.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.zyh.entity.Type;
import com.qf.zyh.services.Impl.TypeSerImpl;
import com.qf.zyh.services.TypeSer;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/type")
public class TypeCont extends BaseServlet{
    private TypeSer ts = new TypeSerImpl();
    public String getAll(HttpServletRequest request, HttpServletResponse response){
        try {
            List<Type> all = ts.getAll();
            ObjectMapper obj = new ObjectMapper();
            //转换成字符串
            String s = obj.writeValueAsString(all);
            return s;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
